package com.ymatou.iapi.tradesafe.testcase;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.http.client.ClientProtocolException;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonObject;
import com.ymatou.iapi.optrade.parameter.enums.CancelOrderTypeEnum;
import com.ymatou.iapi.optrade.parameter.enums.LogisticsTypeEnum;
import com.ymatou.iapi.optrade.resp.TradingServiceResp;
import com.ymatou.iapi.tradesafe.parameter.AcceptOrderBean;
import com.ymatou.iapi.tradesafe.parameter.CancelOrderRequest;
import com.ymatou.iapi.tradesafe.parameter.OrderDetailItem;
import com.ymatou.iapi.tradesafe.parameter.OrderItem;
import com.ymatou.iapi.tradesafe.service.AcceptOrderCall;
import com.ymatou.iapi.tradesafe.service.CancelOrderCall;
import com.ymatou.iapi.userregister.parameter.UserRegisterInfoRequestDtoBean;
import com.ymatou.iapi.userregister.service.UserRegisterInfoRequestDtoCall;
import com.ymatou.mq.admin.parameter.MessageListBean;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.business.service.MqQueryCallService;
import com.ymttest.business.service.YMTTrading.TradingCallService;
import com.ymttest.business.service.YMTTrading.TradingPlaceOrderCallService;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.TestDataManager;

/**
 * 风控接单 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_AcceptOrder {
	private static AcceptOrderBean acceptorderBean;
	private static AcceptOrderCall acceptorderCall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("风控接单");
	}

	@Before
	public void caseUp() {
		acceptorderBean = new AcceptOrderBean();
		acceptorderCall = new AcceptOrderCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(acceptorderCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	/**
	 * 初始化风控 一单只有一个子单
	 * 
	 * @param mainOrderId
	 *            主单号
	 * @param orderId
	 *            订单号
	 * @return
	 * @throws IOException
	 * @throws ClientProtocolException
	 */
	private AcceptOrderBean initAcceptorderBean(Long mainOrderId, Long orderId, Integer sellerId, Integer uid) throws ClientProtocolException, IOException {
		AcceptOrderBean AcceptOrderBean = new AcceptOrderBean();
		AcceptOrderBean.setAddress("address");
		AcceptOrderBean.setDeviceId(TestDataManager.getRandomUUID().toString());
		AcceptOrderBean.setExternalPayerId("payid" + TestDataManager.getRandomNum(5));
		AcceptOrderBean.setExternalUserId("euid" + TestDataManager.getRandomNum(5));
		AcceptOrderBean.setMainOrderId(mainOrderId);
		AcceptOrderBean.setMobile(TestDataManager.getPhoneNum());
		List<OrderItem> orderItems = new ArrayList<>();
		OrderItem oi = new OrderItem();
		List<OrderDetailItem> orderDetailItems = new ArrayList<>();
		OrderDetailItem odi = new OrderDetailItem();
		odi.setActivityId("1");
		odi.setCatalogId(TestDataManager.getRandomUUID().toString());
		odi.setProductCount(1);
		odi.setProductId(TestDataManager.getRandomUUID().toString());
		odi.setProductPrice("2.00");
		orderDetailItems.add(odi);
		oi.setOrderDetailItems(orderDetailItems);
		oi.setOrderId(orderId);
		oi.setSellerId(sellerId);
		oi.setSellerName(JUserCallService.GetUserInfo(sellerId).getLoginId());
		oi.setYmtCouponPrice("0.01");
		orderItems.add(oi);
		AcceptOrderBean.setOrderItems(orderItems);
		AcceptOrderBean.setOrderSource("testOrder");
		AcceptOrderBean.setPayChannel("Alipay");
		AcceptOrderBean.setRecipientMobile(TestDataManager.getPhoneNum());
		AcceptOrderBean.setSourceIp(TestDataManager.getRandomIp());
		AcceptOrderBean.setThirdPartyTradingId("tptid" + TestDataManager.getRandomNum(5));
		AcceptOrderBean.setTotalOrderPrice("2.00");
		AcceptOrderBean.setTotalYmtCouponPrice("0.01");
		AcceptOrderBean.setTradingId(mainOrderId.toString());
		AcceptOrderBean.setUserId(uid);
		AcceptOrderBean.setUserName(JUserCallService.GetUserInfo(uid).getLoginId());
		AcceptOrderBean.setYmtCouponBatchCode("100");
		AcceptOrderBean.setYmtCouponCode("200");
		return AcceptOrderBean;
	}

	// 20181108 需求为v5 v6用户如果被风控 则判断最近n天被风控的次数 如果不超过m次则放过然后计数+1 计数按照主单(支付)数量累计
	// 例如 配置 10天3次 30天5次 则一个v5用户被风控后依然可以10天内购买3次 且 30天内购买5次
	//具体策略配置在disconf
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_AcceptOrder_001() {
		Logger.start(true, "风控接单,成功");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			JsonObject result = urrc.getJsonObject().get("Result").getAsJsonObject();
			Integer uid = result.get("UserId").getAsInt();
			JUserCallService.ExpChange(uid, 6);
			TradingServiceResp placeOrderResp = TradingPlaceOrderCallService
					.placeOrderWithThreeProcutInTwoOrder(true,
							BigDecimal.ZERO, uid,
							LogisticsTypeEnum.OVERSEAS_DELIVERY);
			Long orderid = placeOrderResp.getOrderList().get(0).getOrderId();
			acceptorderBean = initAcceptorderBean(placeOrderResp.getTradingId(), orderid, placeOrderResp.getOrderList().get(0).getSellerId().intValue(), uid);
			acceptorderCall.setData(acceptorderBean);
			acceptorderCall.callService();
			Logger.verifyEquals("ok", acceptorderCall.getReturnData(), "返回验证");
			MessageListBean MessageListBean = MqQueryCallService.riskMessage(String.valueOf(placeOrderResp.getOrderList().get(0).getOrderId()));
			List<Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
			if (joa.size() == 0) {
				Thread.sleep(5000);
				joa = MqQueryCallService.GetMqMessage(MessageListBean);
			}
			joa.forEach(ele -> {
				Logger.debug(ele.toString());
				if (orderid.equals(Long.valueOf(ele.get("orderId").toString()))) {
					Logger.debug("orderid:" + orderid);
					Logger.verifyEquals("RiskControl", ele.get("businessType"), "RiskControl");
					Logger.verifyIsContains("PASS", ele.get("paramExt"), "paramExt");
				}
			});
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_AcceptOrder_002() {
		Logger.start(true, "风控接单,被风控");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			JsonObject result = urrc.getJsonObject().get("Result").getAsJsonObject();
			Integer uid = result.get("UserId").getAsInt();
			// JUserCallService.ExpChange(uid, 6);
			TradingServiceResp placeOrderResp = TradingPlaceOrderCallService
					.placeOrderWithThreeProcutInTwoOrder(true,
							BigDecimal.ZERO, uid,
							LogisticsTypeEnum.OVERSEAS_DELIVERY);
			Long orderid = placeOrderResp.getOrderList().get(0).getOrderId();
			acceptorderBean = initAcceptorderBean(placeOrderResp.getTradingId(), orderid, placeOrderResp.getOrderList().get(0).getSellerId().intValue(), uid);
			acceptorderBean.setTotalOrderPrice("20001.00");
			acceptorderBean.getOrderItems().get(0).setOrderPrice("20001.00");
			acceptorderCall.setData(acceptorderBean);
			acceptorderCall.callService();
			Logger.verifyEquals("ok", acceptorderCall.getReturnData(), "返回验证");
			MessageListBean MessageListBean = MqQueryCallService.riskMessage(String.valueOf(placeOrderResp.getOrderList().get(0).getOrderId()));
			List<Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
			if (joa.size() == 0) {
				Thread.sleep(5000);
				joa = MqQueryCallService.GetMqMessage(MessageListBean);
			}
			joa.forEach(ele -> {
				Logger.debug(ele.toString());
				if (orderid.equals(Long.valueOf(ele.get("orderId").toString()))) {
					Logger.debug("orderid:" + orderid);
					Logger.verifyEquals("RiskControl", ele.get("businessType"), "RiskControl");
					Logger.verifyIsContains("REJECTED", ele.get("paramExt"), "paramExt");
				}
			});
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_AcceptOrder_003() {
		Logger.start(true, "风控接单,V5用户被风控放过");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			JsonObject result = urrc.getJsonObject().get("Result").getAsJsonObject();
			Integer uid = result.get("UserId").getAsInt();
			JUserCallService.ExpChange(uid, 5);
			TradingServiceResp placeOrderResp = TradingPlaceOrderCallService
					.placeOrderWithThreeProcutInTwoOrder(true,
							BigDecimal.ZERO, uid,
							LogisticsTypeEnum.OVERSEAS_DELIVERY);
			Long orderid = placeOrderResp.getOrderList().get(0).getOrderId();
			acceptorderBean = initAcceptorderBean(placeOrderResp.getTradingId(), orderid, placeOrderResp.getOrderList().get(0).getSellerId().intValue(), uid);
			acceptorderBean.setTotalOrderPrice("20001.00");
			acceptorderBean.getOrderItems().get(0).setOrderPrice("20001.00");
			acceptorderCall.setData(acceptorderBean);
			acceptorderCall.callService();
			Logger.verifyEquals("ok", acceptorderCall.getReturnData(), "返回验证");
			MessageListBean MessageListBean = MqQueryCallService.riskMessage(String.valueOf(placeOrderResp.getOrderList().get(0).getOrderId()));
			List<Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
			if (joa.size() == 0) {
				Thread.sleep(5000);
				joa = MqQueryCallService.GetMqMessage(MessageListBean);
			}
			joa.forEach(ele -> {
				Logger.debug(ele.toString());
				if (orderid.equals(Long.valueOf(ele.get("orderId").toString()))) {
					Logger.debug("orderid:" + orderid);
					Logger.verifyEquals("RiskControl", ele.get("businessType"), "RiskControl");
					Logger.verifyIsContains("PASS", ele.get("paramExt"), "paramExt");
				}
			});
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_AcceptOrder_004() {
		Logger.start(true, "风控接单,V6用户被风控放过");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			JsonObject result = urrc.getJsonObject().get("Result").getAsJsonObject();
			Integer uid = result.get("UserId").getAsInt();
			JUserCallService.ExpChange(uid, 6);
			TradingServiceResp placeOrderResp = TradingPlaceOrderCallService
					.placeOrderWithThreeProcutInTwoOrder(true,
							BigDecimal.ZERO, uid,
							LogisticsTypeEnum.OVERSEAS_DELIVERY);
			Long orderid = placeOrderResp.getOrderList().get(0).getOrderId();
			acceptorderBean = initAcceptorderBean(placeOrderResp.getTradingId(), orderid, placeOrderResp.getOrderList().get(0).getSellerId().intValue(), uid);
			acceptorderBean.setTotalOrderPrice("20001.00");
			acceptorderBean.getOrderItems().get(0).setOrderPrice("20001.00");
			acceptorderCall.setData(acceptorderBean);
			acceptorderCall.callService();
			Logger.verifyEquals("ok", acceptorderCall.getReturnData(), "返回验证");
			MessageListBean MessageListBean = MqQueryCallService.riskMessage(String.valueOf(placeOrderResp.getOrderList().get(0).getOrderId()));
			List<Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
			if (joa.size() == 0) {
				Thread.sleep(5000);
				joa = MqQueryCallService.GetMqMessage(MessageListBean);
			}
			joa.forEach(ele -> {
				Logger.debug(ele.toString());
				if (orderid.equals(Long.valueOf(ele.get("orderId").toString()))) {
					Logger.debug("orderid:" + orderid);
					Logger.verifyEquals("RiskControl", ele.get("businessType"), "RiskControl");
					Logger.verifyIsContains("PASS", ele.get("paramExt"), "paramExt");
				}
			});
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_AcceptOrder_005() {
		Logger.start(true, "风控接单,V6用户被风控n次后拦截");
		try {
			int num=1;
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			JsonObject result = urrc.getJsonObject().get("Result").getAsJsonObject();
			Integer uid = result.get("UserId").getAsInt();
			JUserCallService.ExpChange(uid, 6);
			// TradingServiceResp placeOrderResp =
			// TradingCallService.placeOrder3(true, false, uid);
			for (int i = 0; i < 5; i++) {
				Long mainorderid = TradingCallService.genMainOrderId(uid);
				Long orderid = TradingCallService.genMainOrderId(uid);
				acceptorderBean = initAcceptorderBean(mainorderid, orderid, Integer.valueOf(EnvSetup.getData("autotest_seller1").toString()), uid);
				acceptorderBean.setTotalOrderPrice("20001.00");
				acceptorderBean.getOrderItems().get(0).setOrderPrice("20001.00");
				acceptorderCall.setData(acceptorderBean);
				acceptorderCall.callService();
				Logger.verifyEquals("ok", acceptorderCall.getReturnData(), "返回验证");
				MessageListBean MessageListBean = MqQueryCallService.riskMessage(orderid.toString());
				List<Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
				if (joa.size() == 0) {
					Thread.sleep(5000);
					joa = MqQueryCallService.GetMqMessage(MessageListBean);
				}
				if (i < num) {
					joa.forEach(ele -> {
						Logger.debug(ele.toString());
						if (orderid.equals(Long.valueOf(ele.get("orderId").toString()))) {
							Logger.debug("orderid:" + orderid);
							Logger.verifyEquals("RiskControl", ele.get("businessType"), "RiskControl");
							Logger.verifyIsContains("PASS", ele.get("paramExt"), "paramExt");
						}
					});
				} else {
					joa.forEach(ele -> {
						Logger.debug(ele.toString());
						if (orderid.equals(Long.valueOf(ele.get("orderId").toString()))) {
							Logger.debug("orderid:" + orderid);
							Logger.verifyEquals("RiskControl", ele.get("businessType"), "RiskControl");
							Logger.verifyIsContains("REJECTED", ele.get("paramExt"), "paramExt");
						}
					});
				}
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	//问题 总线会搜索不出来-需要登入http://tradesafeadmin.ymatou.cn/ 查看后台实际风控情况
	public void Tc_AcceptOrder_006() {
		Logger.start(true, "风控接单-20200129");
		try {
			//指定活动限购风控 mock 总金额10000~20000通过 20000+风控
			//sit设置活动限购N天1次 新客有2倍的风控放宽--临时改代码关闭规则
			//同一个人 同一个收货人手机号 同一个支付账号的自然人维度风控
			//bug- 第一次不是活动限购 第二次传活动id不应该被限购 现在限购了
			//多个活动之间不影响-11活动购买后12活动依然可以买
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			JsonObject result = urrc.getJsonObject().get("Result").getAsJsonObject();
			Integer uid = result.get("UserId").getAsInt();
			JUserCallService.ExpChange(uid, 6);
			TradingServiceResp placeOrderResp = TradingPlaceOrderCallService
					.placeOrderWithThreeProcutInTwoOrder(true,
							BigDecimal.ZERO, uid,
							LogisticsTypeEnum.OVERSEAS_DELIVERY);
			Long orderid = placeOrderResp.getOrderList().get(0).getOrderId();
			acceptorderBean = initAcceptorderBean(placeOrderResp.getTradingId(), orderid, placeOrderResp.getOrderList().get(0).getSellerId().intValue(), uid);
			String mobile=acceptorderBean.getMobile();
			String tid=acceptorderBean.getExternalUserId();
			acceptorderBean.setTotalOrderPrice("15000");
			acceptorderBean.getOrderItems().get(0).getOrderDetailItems().get(0).setActivityId("193838");
			acceptorderBean.setRecipientMobile(mobile);
			acceptorderCall.setData(acceptorderBean);
			acceptorderCall.callService();
			Logger.verifyEquals("ok", acceptorderCall.getReturnData(), "返回验证");
			MessageListBean MessageListBean = MqQueryCallService.riskMessage(String.valueOf(placeOrderResp.getOrderList().get(0).getOrderId()));
			List<Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
			if (joa.size() == 0) {
				Thread.sleep(5000);
				joa = MqQueryCallService.GetMqMessage(MessageListBean);
			}
			joa.forEach(ele -> {
				Logger.debug(ele.toString());
				if (orderid.equals(Long.valueOf(ele.get("orderId").toString()))) {
					Logger.debug("orderid:" + orderid);
					Logger.verifyEquals("RiskControl", ele.get("businessType"), "RiskControl");
					Logger.verifyIsContains("pass", ele.get("paramExt"), "paramExt");
				}
			});
			
			
			UserRegisterInfoRequestDtoBean regbean2 = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc2 = JUserCallService.UserRegisterInfoRequestDtoCall(regbean2);
			JsonObject result2 = urrc2.getJsonObject().get("Result").getAsJsonObject();
			Integer uid2 = result2.get("UserId").getAsInt();
			JUserCallService.ExpChange(uid2, 6);
			TradingServiceResp placeOrderResp2 = TradingPlaceOrderCallService
					.placeOrderWithThreeProcutInTwoOrder(true,
							BigDecimal.ZERO, uid,
							LogisticsTypeEnum.OVERSEAS_DELIVERY);
			Long orderid2 = placeOrderResp2.getOrderList().get(0).getOrderId();
			acceptorderBean = initAcceptorderBean(placeOrderResp2.getTradingId(), orderid2, placeOrderResp2.getOrderList().get(0).getSellerId().intValue(), uid2);
			acceptorderBean.setTotalOrderPrice("15000");
			acceptorderBean.setExternalUserId(tid);
			acceptorderBean.setMobile(mobile);
			acceptorderBean.setRecipientMobile(mobile);
			acceptorderBean.getOrderItems().get(0).getOrderDetailItems().get(0).setActivityId("193838");
			acceptorderBean.setYmtCouponBatchCode(null);
			acceptorderBean.setYmtCouponCode(null);
			acceptorderCall.setData(acceptorderBean);
			acceptorderCall.callService();
			Logger.verifyEquals("ok", acceptorderCall.getReturnData(), "返回验证");
			MessageListBean MessageListBean2 = MqQueryCallService.riskMessage(String.valueOf(placeOrderResp2.getOrderList().get(0).getOrderId()));
			List<Map> joa2 = MqQueryCallService.GetMqMessage(MessageListBean2);
			if (joa2.size() == 0) {
				Thread.sleep(5000);
				joa2 = MqQueryCallService.GetMqMessage(MessageListBean2);
			}
			joa2.forEach(ele -> {
				Logger.debug(ele.toString());
				if (orderid.equals(Long.valueOf(ele.get("orderId").toString()))) {
					Logger.debug("orderid:" + orderid);
					Logger.verifyEquals("RiskControl", ele.get("businessType"), "RiskControl");
					Logger.verifyIsContains("rejected", ele.get("paramExt"), "paramExt");
				}
			});
			
			UserRegisterInfoRequestDtoBean regbean3 = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc3 = JUserCallService.UserRegisterInfoRequestDtoCall(regbean3);
			JsonObject result3 = urrc3.getJsonObject().get("Result").getAsJsonObject();
			Integer uid3 = result3.get("UserId").getAsInt();
			JUserCallService.ExpChange(uid3, 6);
			TradingServiceResp placeOrderResp3 = TradingPlaceOrderCallService
					.placeOrderWithThreeProcutInTwoOrder(true,
							BigDecimal.ZERO, uid,
							LogisticsTypeEnum.OVERSEAS_DELIVERY);
			Long orderid3 = placeOrderResp3.getOrderList().get(0).getOrderId();
			acceptorderBean = initAcceptorderBean(placeOrderResp3.getTradingId(), orderid3, placeOrderResp3.getOrderList().get(0).getSellerId().intValue(), uid3);
			acceptorderBean.setTotalOrderPrice("15000");
			acceptorderBean.setExternalUserId(tid);
			acceptorderBean.setMobile(mobile);
			acceptorderBean.setRecipientMobile(mobile);
			acceptorderBean.getOrderItems().get(0).getOrderDetailItems().get(0).setActivityId("12");
			acceptorderCall.setData(acceptorderBean);
			acceptorderCall.callService();
			Logger.verifyEquals("ok", acceptorderCall.getReturnData(), "返回验证");
			MessageListBean MessageListBean3 = MqQueryCallService.riskMessage(String.valueOf(placeOrderResp3.getOrderList().get(0).getOrderId()));
			List<Map> joa3 = MqQueryCallService.GetMqMessage(MessageListBean3);
			if (joa3.size() == 0) {
				Thread.sleep(5000);
				joa3 = MqQueryCallService.GetMqMessage(MessageListBean3);
			}
			joa3.forEach(ele -> {
				Logger.debug(ele.toString());
				if (orderid.equals(Long.valueOf(ele.get("orderId").toString()))) {
					Logger.debug("orderid:" + orderid);
					Logger.verifyEquals("RiskControl", ele.get("businessType"), "RiskControl");
					Logger.verifyIsContains("pass", ele.get("paramExt"), "paramExt");
				}
			});
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_AcceptOrder_007() {
		Logger.start(true, "风控接单-20200201-取消订单减限购计数");
		try {
			//订单取消后可以再次购买-type123 的取消
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			JsonObject result = urrc.getJsonObject().get("Result").getAsJsonObject();
			Integer uid = result.get("UserId").getAsInt();
			JUserCallService.ExpChange(uid, 6);
			TradingServiceResp placeOrderResp = TradingPlaceOrderCallService
					.placeOrderWithThreeProcutInTwoOrder(true,
							BigDecimal.ZERO, uid,
							LogisticsTypeEnum.OVERSEAS_DELIVERY);
			Long orderid = placeOrderResp.getOrderList().get(0).getOrderId();
			Long orderid_2 = placeOrderResp.getOrderList().get(1).getOrderId();
			acceptorderBean = initAcceptorderBean(placeOrderResp.getTradingId(), orderid, placeOrderResp.getOrderList().get(0).getSellerId().intValue(), uid);
			String mobile=acceptorderBean.getMobile();
			String tid=acceptorderBean.getExternalUserId();
			acceptorderBean.setTotalOrderPrice("15000");
			acceptorderBean.getOrderItems().get(0).getOrderDetailItems().get(0).setActivityId("193838");
			acceptorderBean.setRecipientMobile(mobile);
			acceptorderCall.setData(acceptorderBean);
			acceptorderCall.callService();
			Logger.verifyEquals("ok", acceptorderCall.getReturnData(), "返回验证");
			MessageListBean MessageListBean = MqQueryCallService.riskMessage(String.valueOf(placeOrderResp.getOrderList().get(0).getOrderId()));
			List<Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
			if (joa.size() == 0) {
				Thread.sleep(5000);
				joa = MqQueryCallService.GetMqMessage(MessageListBean);
			}
			joa.forEach(ele -> {
				Logger.debug(ele.toString());
				if (orderid.equals(Long.valueOf(ele.get("orderId").toString()))) {
					Logger.debug("orderid:" + orderid);
					Logger.verifyEquals("RiskControl", ele.get("businessType"), "RiskControl");
					Logger.verifyIsContains("pass", ele.get("paramExt"), "paramExt");
				}
			});
			
			
			UserRegisterInfoRequestDtoBean regbean2 = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc2 = JUserCallService.UserRegisterInfoRequestDtoCall(regbean2);
			JsonObject result2 = urrc2.getJsonObject().get("Result").getAsJsonObject();
			Integer uid2 = result2.get("UserId").getAsInt();
			JUserCallService.ExpChange(uid2, 6);
			TradingServiceResp placeOrderResp2 = TradingPlaceOrderCallService
					.placeOrderWithThreeProcutInTwoOrder(true,
							BigDecimal.ZERO, uid,
							LogisticsTypeEnum.OVERSEAS_DELIVERY);
			Long orderid2 = placeOrderResp2.getOrderList().get(0).getOrderId();
			acceptorderBean = initAcceptorderBean(placeOrderResp2.getTradingId(), orderid2, placeOrderResp2.getOrderList().get(0).getSellerId().intValue(), uid2);
			acceptorderBean.setTotalOrderPrice("15000");
			acceptorderBean.setExternalUserId(tid);
			acceptorderBean.setMobile(mobile);
			acceptorderBean.setRecipientMobile(mobile);
			acceptorderBean.getOrderItems().get(0).getOrderDetailItems().get(0).setActivityId("193838");
			acceptorderBean.setYmtCouponBatchCode(null);
			acceptorderBean.setYmtCouponCode(null);
			acceptorderCall.setData(acceptorderBean);
			acceptorderCall.callService();
			Logger.verifyEquals("ok", acceptorderCall.getReturnData(), "返回验证");
			MessageListBean MessageListBean2 = MqQueryCallService.riskMessage(String.valueOf(placeOrderResp2.getOrderList().get(0).getOrderId()));
			List<Map> joa2 = MqQueryCallService.GetMqMessage(MessageListBean2);
			if (joa2.size() == 0) {
				Thread.sleep(5000);
				joa2 = MqQueryCallService.GetMqMessage(MessageListBean2);
			}
			joa2.forEach(ele -> {
				Logger.debug(ele.toString());
				if (orderid.equals(Long.valueOf(ele.get("orderId").toString()))) {
					Logger.debug("orderid:" + orderid);
					Logger.verifyEquals("RiskControl", ele.get("businessType"), "RiskControl");
					Logger.verifyIsContains("rejected", ele.get("paramExt"), "paramExt");
				}
			});
			TradingCallService.cancelOrder(orderid,
					CancelOrderTypeEnum.CUSTOMER_CANCEL_ORDER, uid);
			UserRegisterInfoRequestDtoBean regbean3 = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc3 = JUserCallService.UserRegisterInfoRequestDtoCall(regbean3);
			JsonObject result3 = urrc3.getJsonObject().get("Result").getAsJsonObject();
			Integer uid3 = result3.get("UserId").getAsInt();
			JUserCallService.ExpChange(uid3, 6);
			TradingServiceResp placeOrderResp3 = TradingPlaceOrderCallService
					.placeOrderWithThreeProcutInTwoOrder(true,
							BigDecimal.ZERO, uid,
							LogisticsTypeEnum.OVERSEAS_DELIVERY);
			Long orderid3 = placeOrderResp3.getOrderList().get(0).getOrderId();
			acceptorderBean = initAcceptorderBean(placeOrderResp3.getTradingId(), orderid3, placeOrderResp3.getOrderList().get(0).getSellerId().intValue(), uid3);
			acceptorderBean.setTotalOrderPrice("15000");
			acceptorderBean.setExternalUserId(tid);
			acceptorderBean.setMobile(mobile);
			acceptorderBean.setRecipientMobile(mobile);
			acceptorderBean.getOrderItems().get(0).getOrderDetailItems().get(0).setActivityId("193838");
			acceptorderCall.setData(acceptorderBean);
			acceptorderCall.callService();
			Logger.verifyEquals("ok", acceptorderCall.getReturnData(), "返回验证");
			MessageListBean MessageListBean3 = MqQueryCallService.riskMessage(String.valueOf(placeOrderResp3.getOrderList().get(0).getOrderId()));
			List<Map> joa3 = MqQueryCallService.GetMqMessage(MessageListBean3);
			if (joa3.size() == 0) {
				Thread.sleep(5000);
				joa3 = MqQueryCallService.GetMqMessage(MessageListBean3);
			}
			joa3.forEach(ele -> {
				Logger.debug(ele.toString());
				if (orderid.equals(Long.valueOf(ele.get("orderId").toString()))) {
					Logger.debug("orderid:" + orderid);
					Logger.verifyEquals("RiskControl", ele.get("businessType"), "RiskControl");
					Logger.verifyIsContains("pass", ele.get("paramExt"), "paramExt");
				}
			});
			this.cacelOrderRisk(orderid_2, "1");
			UserRegisterInfoRequestDtoBean regbean4 = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc4 = JUserCallService.UserRegisterInfoRequestDtoCall(regbean4);
			JsonObject result4 = urrc4.getJsonObject().get("Result").getAsJsonObject();
			Integer uid4 = result4.get("UserId").getAsInt();
			JUserCallService.ExpChange(uid4, 6);
			TradingServiceResp placeOrderResp4 = TradingPlaceOrderCallService
					.placeOrderWithThreeProcutInTwoOrder(true,
							BigDecimal.ZERO, uid,
							LogisticsTypeEnum.OVERSEAS_DELIVERY);
			Long orderid4 = placeOrderResp4.getOrderList().get(0).getOrderId();
			acceptorderBean = initAcceptorderBean(placeOrderResp4.getTradingId(), orderid4, placeOrderResp4.getOrderList().get(0).getSellerId().intValue(), uid4);
			acceptorderBean.setTotalOrderPrice("15000");
			acceptorderBean.setExternalUserId(tid);
			acceptorderBean.setMobile(mobile);
			acceptorderBean.setRecipientMobile(mobile);
			acceptorderBean.getOrderItems().get(0).getOrderDetailItems().get(0).setActivityId("193838");
			acceptorderCall.setData(acceptorderBean);
			acceptorderCall.callService();
			Logger.verifyEquals("ok", acceptorderCall.getReturnData(), "返回验证");
			MessageListBean MessageListBean4 = MqQueryCallService.riskMessage(String.valueOf(placeOrderResp4.getOrderList().get(0).getOrderId()));
			List<Map> joa4 = MqQueryCallService.GetMqMessage(MessageListBean4);
			if (joa4.size() == 0) {
				Thread.sleep(5000);
				joa4 = MqQueryCallService.GetMqMessage(MessageListBean4);
			}
			joa4.forEach(ele -> {
				Logger.debug(ele.toString());
				if (orderid.equals(Long.valueOf(ele.get("orderId").toString()))) {
					Logger.debug("orderid:" + orderid);
					Logger.verifyEquals("RiskControl", ele.get("businessType"), "RiskControl");
					Logger.verifyIsContains("pass", ele.get("paramExt"), "paramExt");
				}
			});
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	/**
	 * 风控取消
	 * @param orderid
	 * @param ctype
	 * //买家取消
    BUYER_CANCEL_ORDER(1),
    //卖家取消
    SELLER_CANCEL_ORDER(2),
    //客服取消
    CUSTOMER_CANCEL_ORDER(3),
    //系统取消
    SYSTEM_CANCEL_ORDER(4),
    //风控取
    RISKCONTROL(5),
    //砍价团取消
    BARGAINGROUP(6),
    //超过每年20000限额
    EXCEEDLIMIT(7);
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	private void cacelOrderRisk(Long orderid,String ctype) throws ClientProtocolException, IOException {
		CancelOrderRequest CancelOrderRequest=new com.ymatou.iapi.tradesafe.parameter.CancelOrderRequest();
		CancelOrderRequest.setOrderId(orderid);
		Map<String, String> paramExt=new HashMap<String, String>();
		paramExt.put("CancelType", ctype);
		CancelOrderRequest.setParamExt(paramExt);
		CancelOrderCall CancelOrderCall=new com.ymatou.iapi.tradesafe.service.CancelOrderCall();
		CancelOrderCall.setData(CancelOrderRequest);
		CancelOrderCall.callService();
	}
}